package com.shuidihuzhu.sdb.service.data;

import com.shuidihuzhu.sdb.helper.log.utils.JsonUtil;
import org.junit.Test;
import org.springframework.boot.json.JsonParser;
import org.springframework.core.io.ClassPathResource;

import java.io.InputStream;
import java.util.List;
import java.util.Map;

public class DataParse {
    @Test
    public void parse() throws Exception {
        final ClassPathResource resource1 = new ClassPathResource("/data/msg1.json");
        final ClassPathResource resource2 = new ClassPathResource("/data/msg2.json");
        for (ClassPathResource resource : List.of(resource1, resource2)) {
            try(InputStream inputStream = resource.getInputStream()) {
                Map map = JsonUtil.fromJson(inputStream, Map.class);
                map = (Map) map.get("rawResponse");
                map = (Map) map.get("hits");
                List<Map> list = (List) map.get("hits");
                System.out.println(list.get(0).get("_source").getClass());
                for (Map item : list) {
                    final Object source = item.get("_source");
                    System.out.println(source.getClass());
                }
            }
        }
    }
}
